//
//  ZTYNetWorking.m
//  ZXKlineDemo
//
//  Created by wanmeizty on 2018/5/2.
//  Copyright © 2018年 郑旭. All rights reserved.
//

#import "ZTYNetWorking.h"
#import <AFNetworking.h>
@implementation ZTYNetWorking
+ (void)postnetWorkingUrl:(NSString *)urlString params:(NSDictionary *)params sucess:(void(^)(NSDictionary * response))sucess failure:(void(^)(NSError * error))failure{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithArray:@[@"application/json",
                                                                              @"text/html",
                                                                              @"text/json",
                                                                              @"text/plain",
                                                                              @"text/javascript",
                                                                              @"text/xml",
                                                                              @"image/*"]];
    
    [manager POST:urlString parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            !sucess ? : sucess(responseObject);
        });
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            !failure?:failure(error);
        });
        
    }];
}

+ (void)getnetWorkingUrl:(NSString *)urlString params:(NSDictionary *)params sucess:(void(^)(NSDictionary * response))sucess failure:(void(^)(NSError * error))failure{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithArray:@[@"application/json",
                                                                              @"text/html",
                                                                              @"text/json",
                                                                              @"text/plain",
                                                                              @"text/javascript",
                                                                              @"text/xml",
                                                                              @"image/*"]];
    [manager GET:urlString parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        
        dispatch_async(dispatch_get_main_queue(), ^{
            !sucess ? : sucess(responseObject);
        });
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"error===>%@",error);
        dispatch_async(dispatch_get_main_queue(), ^{
            !failure?:failure(error);
        });
    }];
    
}

@end
